<?php
	include_once 'isLogin.php';
	$userc=new user();
	$table= 'user_message';  	  		 	  //咨询表

	$id=$_GET['id'];
	$admin_id=$_COOKIE['admin_id'];


	if($_POST['submit']){
		$user_id=$_POST['user_id'];
		$user_id=substr($user_id,0,-1);
		if($user_id){
			$user_id=explode(',',$user_id);
			//批量数组
			if(is_array($user_id)){
				foreach ($user_id as $k => $v) {
					$list[$k]= array('to_user'=>$v,);
				}
			}
			//单数组
			$arr= array('title' =>$_POST['title'],
						'content' =>$_POST['intro'],
						'admin_id'=>$admin_id,
						'create_time'=>time(),
					);

			$res=$userc->message_add($arr,$list);	
			if($res){
				$msg="操作成功";
				$href="user_message_list.php";
			}else{
				$msg="操作失败";
				$href="user_message_list.php";
			}
			echo $commonc->submitAlert($msg,$href);
			exit;

		}else{
			echo $commonc->submitAlert("未选择用户","user_message_add.php");
			exit;

		}

	}



	//读取用户
	$where.=' order by u.id desc';
	$key='u.*,FROM_UNIXTIME(u.reg_time,"%Y-%m-%d") as regTime';
	$user=$userc->userList($where,$key,1);
	$smarty->assign('user',$user['result']);
	
	$smarty->display("user_message_add.html");
?>